if BossSpawner == nil then
    BossSpawner = {}
    BossSpawner.__index = BossSpawner
end

function BossSpawner:new( o )
    o = o or {}
    setmetatable( o, BossSpawner )
    return o
end


function BossSpawner:Init()
    BossSpawner.boss=nil
end

function BossSpawner:GetRefreshTime()
    local refreshTime=RandomInt(SpawnBossConfig["boss_spawner"].minRandomRefreshTime,SpawnBossConfig["boss_spawner"].maxRandomRefreshTime)
    print("[GetRefreshTime]",refreshTime)
    return  refreshTime
end

function BossSpawner:Start()
    if BossSpawner.boss==nil then
        BossSpawner.boss=CreateUnitByName("npc_money_tree" , Map.bossPos, true, nil, nil, DOTA_TEAM_NEUTRALS )
        BossSpawner.boss:AddNewModifier(BossSpawner.boss,nil,AbilitiesNames.modifier_dummy,{})
    end
    Timers:CreateTimer(SpawnBossConfig["boss_spawner"].firstRefreshTime,function()
            MsgUtil:TopToAll({text="#InfoTip_Boss_Area_Open", style={color=ColorHex.Warn}})
            EmitGlobalSound(SoundsNames.warning)

            local index,pos= Hero:GetRandomSpawnPos()
            pos=Vector(pos.x,pos.y,pos.z+100)
            print("boss pos..",index,pos)
            Map.bossTp.firstActivator=nil
            Map.bossTp.mapPosIndex=index
            Map.bossTp:SetAbsOrigin(pos)
            Map.bossTp.particle:SetAbsOrigin(pos)
        for _,hero in pairs(Hero.heroList)do
            MinimapEvent( hero:GetTeamNumber(), hero, Map.bossTp:GetAbsOrigin().x, Map.bossTp:GetAbsOrigin().y, DOTA_MINIMAP_EVENT_HINT_LOCATION, 6 )
        end
        return BossSpawner:GetRefreshTime()
    end)
end

--function BossSpawner:StartSpawn(hero)
--    if BossSpawner.boss~=nil then
--        BossSpawner.boss:RemoveModifierByName(AbilitiesNames.modifier_boss)
--        BossSpawner.boss:AddNewModifier(BossSpawner.boss,nil,AbilitiesNames.modifier_boss,{playerId=hero:GetPlayerID()})
--        return
--    end
--    local bosses= Unit:GetRandomSpawnBoss(1)
--    for i=1,#bosses do
--        print("start spawn")
--        local dummy=Hero:FastDummy(Map.bossPos,DOTA_TEAM_NEUTRALS,3)
--        local particle1= ParticleManager:CreateParticle(ParticleNames.spawn_boss_show, PATTACH_ABSORIGIN_FOLLOW,dummy)
--        dummy:EmitSound(SoundsNames.spawn_boss_show)
--        Timers:CreateTimer(3,function ()
--            ParticleManager:DestroyParticle( particle1, true )
--            ParticleManager:ReleaseParticleIndex(particle1)
--            local boss= CreateUnitByName(bosses[i] , Map.bossPos, true, nil, nil, DOTA_TEAM_NEUTRALS )
--            BossSpawner.boss=boss
--            local lv=boss:GetLevel()
--            local damage=(SpawnConfig.attack*1.5)*SpawnConfig.attackRate^(lv)
--            local hp=(SpawnConfig.hp*1.5)*SpawnConfig.hpRate^(lv-1)
--            print("[StartSpawn] hp=",hp)
--            boss:SetMinimumGoldBounty(0);
--            boss:SetMaximumGoldBounty(0);
--            boss:SetMana(lv*200);
--            boss:SetDeathXP(0)
--            boss:SetHealth(hp)
--            boss:SetMaxHealth(hp)
--            boss:SetBaseMaxHealth(hp)
--            boss:ModifyHealth(hp, nil, true, 0)
--            boss:SetBaseDamageMax(damage)
--            boss:SetBaseDamageMin(damage)
--            boss:SetPhysicalArmorBaseValue(1)
--
--            boss:AddNewModifier(boss,nil,AbilitiesNames.modifier_boss,{playerId=hero:GetPlayerID()})
--            boss:EmitSound(SoundsNames.spawn_boss)
--            local particle=ParticleManager:CreateParticle(ParticleNames.spawn_boss_buff, PATTACH_ABSORIGIN_FOLLOW, boss)
--            ParticleManager:ReleaseParticleIndex(particle)
--            particle=ParticleManager:CreateParticle(ParticleNames.spawn_boss_buff2, PATTACH_ABSORIGIN_FOLLOW, boss)
--            ParticleManager:SetParticleControl(particle, 0,boss:GetAbsOrigin())
--            ParticleManager:SetParticleControl(particle, 1,Vector(1,0,0))
--            ParticleManager:ReleaseParticleIndex(particle)
--        end)
--    end
--end

function BossSpawner:StartSpawn(hero)
    if BossSpawner.boss:IsAlive()~=true then
        BossSpawner.boss:RespawnUnit()
    end
    BossSpawner.boss:Heal(BossSpawner.boss:GetMaxHealth(),BossSpawner.boss)
    BossSpawner.boss:RemoveModifierByName(AbilitiesNames.modifier_dummy)
    BossSpawner.boss:AddNewModifier(BossSpawner.boss,nil,AbilitiesNames.modifier_money_tree,{playerId=hero:GetPlayerID()})
end